package com.admission.web.admin;

import java.util.List;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.admission.model.Academy;
import com.admission.model.Major;
import com.admission.service.AcademyManager;
import com.admission.service.MajorManager;
import com.admission.util.PageUtils;
import com.admission.web.CrudActionSupport;
@Namespace("/admin")
public class AcademyAdminAction extends CrudActionSupport<Academy>{

	private static final long serialVersionUID = 488185923443490311L;
	private String id;
	private Page<Academy> page = new Page<Academy>(PageUtils.DEFAULT_PAGE_SIZE);
	
	private Academy entity;
	private AcademyManager academyManager;
	private MajorManager majorManager;
	//private Page<Academy> page=new Page<Academy>(10);
	private List<Academy> academyList; //返回所有的学院
	private List<Major> majorList;
	private String state;

	public Academy getModel() {
		return entity;
	}

	@Override
	public String list() throws Exception {
		List<PropertyFilter> filters = PropertyFilter
				.buildFromHttpRequest(Struts2Utils.getRequest());
		page=academyManager.getPageByFilter(page, filters);
		return "list";
	}
   
	@Override
	public String input() throws Exception {
		entity=academyManager.getAcademyById(id);
		return "detail";
	}

	@Override
	public String save() throws Exception {
		try {
			academyManager.save(entity);
		} catch (Exception e) {
		   this.addActionMessage("操作失败，请重新操作");
	    }
		return list();
	}

	@Override
	public String delete() throws Exception {
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		if(StringUtils.isEmpty(id)){
			entity = new Academy();
		}else{
			entity = academyManager.getAcademyById(id);
		}
		
	}
	public String onCheck() throws Exception{
		entity=academyManager.getAcademyById(id);
		academyManager.onCheck(entity, state);
		return list();
	}
	
    public String add() throws Exception{
		   return "add";
	   }
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	public Academy getEntity() {
		return entity;
	}

	public void setEntity(Academy entity) {
		this.entity = entity;
	}
    @Autowired
	public void setAcademyManager(AcademyManager academyManager) {
		this.academyManager = academyManager;
	}

	public List<Academy> getAcademyList() {
		return academyList;
	}

	public void setAcademyList(List<Academy> academyList) {
		this.academyList = academyList;
	}

	public AcademyManager getAcademyManager() {
		return academyManager;
	}

	public MajorManager getMajorManager() {
		return majorManager;
	}
    @Autowired
	public void setMajorManager(MajorManager majorManager) {
		this.majorManager = majorManager;
	}

	public List<Major> getMajorList() {
		return majorList;
	}

	public void setMajorList(List<Major> majorList) {
		this.majorList = majorList;
	}

	public Page<Academy> getPage() {
		return page;
	}

	public void setPage(Page<Academy> page) {
		this.page = page;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}
    
	

}
